IMEC seminar
June 10 2022 - Leuven, BE

Use the Space key to navigate through all slides and SHIFT + Space key to go back one slide.

NB: AbiPy can be interfaced with other packages (e.g ASE, phonopy) via converters.
Layered structure designed for different use-cases:
Closely connected to the ABINIT executable:
ABINIT and AbiPy communicate through netcdf files
Using conda and the conda forge channel (recommended):
conda install abipy --channel conda-forge
Since conda is not limited to python packages, one can install ABINIT in the same env with:
conda install abinit -c conda-forge
Using pip and python wheels:
pip install abipy --user
For further info see this installation howto
%embed https://abinit.github.io/abipy/index.html
%embed https://nbviewer.jupyter.org/github/abinit/abitutorials/blob/master/abitutorials/index.ipynb

abistruct.py --help for manpageabistruct.py COMMAND --help for help about COMMANDHTML documentation available at http://abinit.github.io/abipy/scripts/index.html

!abiopen.py si_scf_GSR.nc --print # or -p
================================= File Info =================================
Name: si_scf_GSR.nc
Directory: /Users/gmatteo/git_repos/abipy_imec_2022
Size: 14.83 kb
Access Time: Mon Jun 6 23:58:53 2022
Modification Time: Mon Jun 6 23:53:36 2022
Change Time: Mon Jun 6 23:53:36 2022
================================= Structure =================================
Full Formula (Si2)
Reduced Formula: Si
abc : 3.866975 3.866975 3.866975
angles: 60.000000 60.000000 60.000000
Sites (2)
# SP a b c cartesian_forces
--- ---- ---- ---- ---- -----------------------------------------------------------
0 Si 0 0 0 [-5.89948306e-27 -1.93366149e-27 2.91016904e-27] eV ang^-1
1 Si 0.25 0.25 0.25 [ 5.89948306e-27 1.93366149e-27 -2.91016904e-27] eV ang^-1
Abinit Spacegroup: spgid: 227, num_spatial_symmetries: 48, has_timerev: True, symmorphic: True
Stress tensor (Cartesian coordinates in GPa):
[[5.21161758e+00 7.86452261e-11 0.00000000e+00]
[7.86452261e-11 5.21161758e+00 0.00000000e+00]
[0.00000000e+00 0.00000000e+00 5.21161758e+00]]
Pressure: -5.212 (GPa)
Energy: -241.23647031 (eV)
============================== Electronic Bands ==============================
Number of electrons: 8.0, Fermi level: 5.598 (eV)
nsppol: 1, nkpt: 29, mband: 8, nspinor: 1, nspden: 1
smearing scheme: none (occopt 1), tsmear_eV: 0.272, tsmear Kelvin: 3157.7
Direct gap:
Energy: 2.532 (eV)
Initial state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000
Final state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 4, eig: 8.130, occ: 0.000
Fundamental gap:
Energy: 0.562 (eV)
Initial state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000
Final state: spin: 0, kpt: [+0.375, +0.375, +0.000], weight: 0.012, band: 4, eig: 6.161, occ: 0.000
Bandwidth: 11.856 (eV)
Valence maximum located at kpt index 0:
spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000
Conduction minimum located at kpt index 17:
spin: 0, kpt: [+0.375, +0.375, +0.000], weight: 0.012, band: 4, eig: 6.161, occ: 0.000
TIP: Use `--verbose` to print k-point coordinates with more digits
abiopen.py mgb2_kpath_FATBANDS.nc --expose --seaborn # or -e -sns

--expose with --notebook to generate notebook with predefined python code¶abiopen.py out_GRUNS.nc --expose-web # -ew for the short version

--panel option:¶abiopen.py out_DDB --panel # or -pn if you prefer the short option.

!abistruct.py convert si_scf_GSR.nc -f cif
# generated using pymatgen data_Si _symmetry_space_group_name_H-M 'P 1' _cell_length_a 3.86697464 _cell_length_b 3.86697464 _cell_length_c 3.86697464 _cell_angle_alpha 60.00000000 _cell_angle_beta 60.00000000 _cell_angle_gamma 60.00000000 _symmetry_Int_Tables_number 1 _chemical_formula_structural Si _chemical_formula_sum Si2 _cell_volume 40.88829233 _cell_formula_units_Z 2 loop_ _symmetry_equiv_pos_site_id _symmetry_equiv_pos_as_xyz 1 'x, y, z' loop_ _atom_site_type_symbol _atom_site_label _atom_site_symmetry_multiplicity _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy Si Si0 1 0.00000000 0.00000000 0.00000000 1 Si Si1 1 0.25000000 0.25000000 0.25000000 1
!abistruct.py kpath si_scf_GSR.nc
/Users/gmatteo/git_repos/pymatgen/pymatgen/symmetry/kpath.py:179: UserWarning: The input structure does not match the expected standard primitive! The path can be incorrect. Use at your own risk.
warn(
# Abinit Structure
natom 2
ntypat 1
typat 1 1
znucl 14
xred
0.0000000000 0.0000000000 0.0000000000
0.2500000000 0.2500000000 0.2500000000
acell 1.0 1.0 1.0
rprim
6.3285005521 0.0000000000 3.6537614973
2.1095001840 5.9665675402 3.6537614973
0.0000000000 0.0000000000 7.3075229946
# tolwfr 1e-20 iscf -2 # NSCF run
# To read previous DEN file, use: getden -1 or specify filename via getden_path "out_DEN"
# K-path in reduced coordinates:
ndivsm 10
kptopt -11
kptbounds
+0.00000 +0.00000 +0.00000 # $\Gamma$
+0.50000 +0.00000 +0.50000 # X
+0.50000 +0.25000 +0.75000 # W
+0.37500 +0.37500 +0.75000 # K
+0.00000 +0.00000 +0.00000 # $\Gamma$
+0.50000 +0.50000 +0.50000 # L
+0.62500 +0.25000 +0.62500 # U
+0.50000 +0.25000 +0.75000 # W
+0.50000 +0.50000 +0.50000 # L
+0.37500 +0.37500 +0.75000 # K
+0.62500 +0.25000 +0.62500 # U
+0.50000 +0.00000 +0.50000 # X
!abistruct.py mp_match si_scf_GSR.nc
# Found 2 structures in Materials Project database (use `verbose` to get further info)
########################### abivars input for this ###########################
# Full Formula (Si2)
# Reduced Formula: Si
# abc : 3.866975 3.866975 3.866975
# angles: 60.000000 60.000000 60.000000
#
# Spglib space group info (magnetic symmetries not taken into account).
# Spacegroup: Fd-3m (227), Hall: F 4d 2 3 -1d, Abinit spg_number: 227
# Crystal_system: cubic, Lattice_type: cubic, Point_group: m-3m
#
# Idx Symbol Reduced_Coords Wyckoff EqIdx
# ----- -------- -------------------------- --------- -------
# 0 Si +0.00000 +0.00000 +0.00000 (2a) 0
# 1 Si +0.25000 +0.25000 +0.25000 (2a) 0
natom 2
ntypat 1
typat 1 1
znucl 14
xred
0.0000000000 0.0000000000 0.0000000000
0.2500000000 0.2500000000 0.2500000000
acell 1.0 1.0 1.0
rprim
6.3285005521 0.0000000000 3.6537614973
2.1095001840 5.9665675402 3.6537614973
0.0000000000 0.0000000000 7.3075229946
########################## abivars input for mp-149 ##########################
# Full Formula (Si2)
# Reduced Formula: Si
# abc : 3.866975 3.866975 3.866975
# angles: 60.000000 60.000000 60.000000
#
# Spglib space group info (magnetic symmetries not taken into account).
# Spacegroup: Fd-3m (227), Hall: F 4d 2 3 -1d, Abinit spg_number: None
# Crystal_system: cubic, Lattice_type: cubic, Point_group: m-3m
#
# Idx Symbol Reduced_Coords Wyckoff EqIdx
# ----- -------- -------------------------- --------- -------
# 0 Si +0.25000 +0.25000 +0.25000 (2b) 0
# 1 Si +0.00000 +0.00000 +0.00000 (2b) 0
natom 2
ntypat 1
typat 1 1
znucl 14
xred
0.2500000000 0.2500000000 0.2500000000
0.0000000000 0.0000000000 0.0000000000
acell 1.0 1.0 1.0
rprim
0.0000000000 5.1671990850 5.1671990850
5.1671990850 0.0000000000 5.1671990850
5.1671990850 5.1671990850 0.0000000000

abiview.py ddb ZnSe_hex_qpt_DDB --seaborn

--phononwebsite to visualize data on the phononwebsite by H. Miranda¶
!abicomp.py structure *.cif si_nscf_GSR.nc *_DDB
Spglib options: symprec= 0.001 angle_tolerance= 5.0
Lattice parameters:
formula natom alpha beta gamma a b \
AlAs.cif Al1 As1 2 60.0 60.0 60.0 3.970101 3.970101
si.cif Si2 2 60.0 60.0 60.0 3.866975 3.866975
si_nscf_GSR.nc Si2 2 60.0 60.0 60.0 3.866975 3.866975
ZnSe_hex_qpt_DDB Zn2 Se2 4 90.0 90.0 120.0 4.050187 4.050187
alas_DDB Al1 As1 2 60.0 60.0 60.0 3.970101 3.970101
elastic_DDB Al2 As2 4 90.0 90.0 120.0 3.989448 3.989448
c volume abispg_num spglib_symb spglib_num \
AlAs.cif 3.970101 44.247584 None F-43m 216
si.cif 3.866975 40.888292 None Fd-3m 227
si_nscf_GSR.nc 3.866975 40.888292 227 Fd-3m 227
ZnSe_hex_qpt_DDB 6.652328 94.504936 0 P6_3mc 186
alas_DDB 3.970101 44.247584 0 F-43m 216
elastic_DDB 6.497130 89.552529 0 P6_3mc 186
spglib_lattice_type
AlAs.cif cubic
si.cif cubic
si_nscf_GSR.nc cubic
ZnSe_hex_qpt_DDB hexagonal
alas_DDB cubic
elastic_DDB hexagonal

Main entry point:
from abipy import abilab
abifile = abilab.abiopen("filename.nc")
where filename.nc is a netcdf file (support also text files e.g. run.abo, run.log, out_DDB)
abifile is the AbiFile subclass associated to the given file extension:
abiopen.py --help) gsr = abiopen("si_nscf_GSR.nc")
gsr.ebands.plot(with_gaps=True);
gsr.ebands.plotly(with_gaps=True); # obj.plot becomes obj.plotly
gsr.ebands.plotly(with_gaps=True, chart_studio=True);

gsr.ebands.kpoints.plotly(title="k-path in 3d with plotly");
znse_ddb = abilab.abiopen("ZnSe_hex_qpt_DDB")
phbst_file, phdos_file = znse_ddb.anaget_phbst_and_phdos_files()
phbands, phdos = phbst_file.phbands, phdos_file.phdos
phbands.plotly_with_phdos(phdos, units="cm-1");
mgo_ddb = abilab.DdbFile.from_mpid("mp-1009129")
print(mgo_ddb)
================================= File Info ================================= Name: mp-1009129chn5l75l_DDB Directory: /var/folders/nc/k69spyd12qv2tk3stk2xrxg40000gr/T Size: 218.73 kb Access Time: Wed Jun 8 20:05:46 2022 Modification Time: Wed Jun 8 20:05:46 2022 Change Time: Wed Jun 8 20:05:46 2022 ================================= Structure ================================= Full Formula (Mg1 O1) Reduced Formula: MgO abc : 2.908638 2.908638 2.656848 angles: 90.000000 90.000000 120.000000 Sites (2) # SP a b c --- ---- -------- -------- --- 0 Mg 0 0 0 1 O 0.333333 0.666667 0.5 Abinit Spacegroup: spgid: 0, num_spatial_symmetries: 12, has_timerev: True, symmorphic: False ================================== DDB Info ================================== Number of q-points in DDB: 72 guessed_ngqpt: [ 9 9 10] (guess for the q-mesh divisions made by AbiPy) ecut = 44.000000, ecutsm = 0.000000, nkpt = 405, nsym = 12, usepaw = 0 nsppol 1, nspinor 1, nspden 1, ixc = -116133, occopt = 1, tsmear = 0.010000 Has total energy: False Has forces: False Has stress tensor: False Has (at least one) atomic pertubation: True Has (at least one diagonal) electric-field perturbation: True Has (at least one) Born effective charge: True Has (all) strain terms: False Has (all) internal strain terms: False Has (all) piezoelectric terms: False Has (all) dynamical quadrupole terms: False
paths = [
"mgb2_888k_0.01tsmear_DDB",
"mgb2_888k_0.04tsmear_DDB",
"mgb2_121212k_0.01tsmear_DDB",
"mgb2_121212k_0.04tsmear_DDB",
]
paths = [os.path.join(abidata.dirpath, "refs", "mgb2_phonons_nkpt_tsmear", f)
for f in paths]
robot = abilab.DdbRobot()
for path in paths:
robot.add_file(path, path)
# Define function to change labels:
func = lambda ddb: "nkpt: %s, tsmear: %.2f" % (
ddb.header["nkpt"], ddb.header["tsmear"])
robot.remap_labels(func)
robot
robot.get_params_dataframe()
| nkpt | nsppol | ecut | tsmear | occopt | ixc | nband | usepaw | |
|---|---|---|---|---|---|---|---|---|
| nkpt: 256, tsmear: 0.01 | 256 | 1 | 35.0 | 0.01 | 4 | 1 | 8 | 0 |
| nkpt: 256, tsmear: 0.04 | 256 | 1 | 35.0 | 0.04 | 4 | 1 | 8 | 0 |
| nkpt: 864, tsmear: 0.01 | 864 | 1 | 35.0 | 0.01 | 4 | 1 | 8 | 0 |
| nkpt: 864, tsmear: 0.04 | 864 | 1 | 35.0 | 0.04 | 4 | 1 | 8 | 0 |
robot.get_lattice_dataframe()
| formula | natom | alpha | beta | gamma | a | b | c | volume | abispg_num | spglib_symb | spglib_num | spglib_lattice_type | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| nkpt: 256, tsmear: 0.01 | Mg1 B2 | 3 | 90.0 | 90.0 | 120.0 | 3.086 | 3.086 | 3.523 | 29.055953 | 0 | P6/mmm | 191 | hexagonal |
| nkpt: 256, tsmear: 0.04 | Mg1 B2 | 3 | 90.0 | 90.0 | 120.0 | 3.086 | 3.086 | 3.523 | 29.055953 | 0 | P6/mmm | 191 | hexagonal |
| nkpt: 864, tsmear: 0.01 | Mg1 B2 | 3 | 90.0 | 90.0 | 120.0 | 3.086 | 3.086 | 3.523 | 29.055953 | 0 | P6/mmm | 191 | hexagonal |
| nkpt: 864, tsmear: 0.04 | Mg1 B2 | 3 | 90.0 | 90.0 | 120.0 | 3.086 | 3.086 | 3.523 | 29.055953 | 0 | P6/mmm | 191 | hexagonal |
# Invoke anaddb and store results
r = robot.anaget_phonon_plotters(nqsmall=2)
r.phbands_plotter.gridplot_with_hue("tsmear", with_dos=True);

NB: There's an ongoing effort to reimplement AbiFlows in terms of the atomate framework. In this talk, we will mainly discuss the new features available in abipy.flowtk.
scheduler.yml providing:
manager.yml providing:
See this page for examples or use the abidoc.py script and the syntax:
def make_scf_input(ecut=2, ngkpt=(4, 4, 4)):
"""
Generate an `AbinitInput` to perform GS calculation for AlAs.
Args:
ecut: Cutoff energy in Ha.
ngkpt: k-mesh divisions
Return:
`AbinitInput` object
"""
gs_inp = abilab.AbinitInput(structure="AlAs.cif",
pseudos=["13al.pspnc", "33as.pspnc"])
# Set the value of the Abinit variables needed for GS runs.
gs_inp.set_vars(
nband=4,
ecut=ecut,
ngkpt=ngkpt,
nshiftk=4,
shiftk=[0.0, 0.0, 0.5, # This gives the usual fcc Monkhorst-Pack grid
0.0, 0.5, 0.0,
0.5, 0.0, 0.0,
0.5, 0.5, 0.5],
tolvrs=1.0e-10,
)
return gs_inp
make_scf_input()
AbiniInput one can easily build more complicate workflows:¶def build_flow_alas_phonons():
"""
Build and return a Flow to compute the dynamical matrix on a (2, 2, 2) qmesh
as well as DDK and Born effective charges.
The final DDB with all perturbations will be merged automatically and placed
in the Flow `outdir` directory.
"""
from abipy import flowtk
scf_input = make_scf_input(ecut=6, ngkpt=(4, 4, 4))
return flowtk.PhononFlow.from_scf_input("flow_alas_phonons", scf_input,
ph_ngqpt=(2, 2, 2), with_becs=True)
flow_phbands = build_flow_alas_phonons()
flow_phbands.get_graphviz()
The simplest way to start the scheduler from the shell is via the syntax:
run_elastic.py --scheduler # -s for the short option
For non-trivial Flows, we suggest to put the scheduler in background and use nohup
so that we can disconnect from the shell session without killing the scheduler.
nohup run_elastic.py --s > log 2> err &
Obviously, it is possible to submit a Slurm script that executes the script on the compute note with 1 core.
To interact with the Flow, one can also use the abirun.py script, e.g:
abirun.py FLOWDIR status

scf_input = make_scf_input() # Build input for GS calculation
elast_work = flowtk.ElasticWork.from_scf_input(scf_input,
with_relaxed_ion=True,
with_piezo=True)

Compute $\epsilon^{\alpha\beta}_{n\bf{k}}$ and the effective mass tensor at the band edges using $|u_{n\mathbf{k}}\rangle$, and the k-derivatives $|u_{n\mathbf{k}}^\alpha\rangle$ $H^\alpha_{\mathbf{k}}$, $H^{\alpha\beta}_{\mathbf{k}}$
For the formalism, see J. Laflamme Janssen, et. al. Phys. Rev. B 93, 205147
flow = flowtk.Flow("flow_effmass_dfpt")
# Build input for GS SCF calculation.
scf_input = make_scf_input()
# This object implements all the worflow logic
from abipy.flowtk.effmass_works import EffMassAutoDFPTWork
work = EffMassAutoDFPTWork.from_scf_input(scf_input)
flow.register_work(work)
